/**
 * 日志统计中间件
 */
const logUtil = require('../utils/logUtil');

module.exports =  () => {
    return async (ctx, next) => {
        const start = new Date();
        let ms;
        try {
            await next();
            ms = new Date() - start;
            //记录响应日志
            logUtil.logResponse(ctx, ms);

        } catch (error) {
            ms = new Date() - start;
            //记录异常日志
            logUtil.logError(ctx, error, ms);
        }
    }
}